home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte25 / ex4.c < prev    next >
C/C++ Source or Header  |  1995-04-23  |  3KB  |  68 lines

  1. #include <genstub.c>
  2.  
  3. LPARAM CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LONG lParam )
  4. {
  5.    switch (message)
  6.       {
  7.        case WM_COMMAND:            // process menu items
  8.            switch ( LOWORD( wParam )  )
  9.            {
  10.                case IDM_TEST:
  11.                {
  12.                    STARTUPINFO si;
  13.                    PROCESS_INFORMATION pi;
  14.                    TCHAR szBuffer[128];
  15.  
  16.                    // initialize structures
  17.                    ZeroMemory( &si, sizeof(STARTUPINFO) );
  18.                    ZeroMemory( &pi, sizeof(PROCESS_INFORMATION) );
  19.                    si.cb=sizeof( STARTUPINFO );
  20.                    si.dwFlags = STARTF_USESHOWWINDOW;
  21.                    si.wShowWindow = SW_SHOWNORMAL;
  22.                    CreateProcess( "C:\\windows\\calc.exe", "", NULL, NULL, FALSE,
  23.                                   0, NULL, NULL, &si, &pi );
  24.  
  25.                    WaitForInputIdle( GetCurrentProcess(), INFINITE );
  26.  
  27.                    // loop until process terminates
  28.                    if (pi.hProcess) {
  29.                       DWORD dwExitCode = STILL_ACTIVE;
  30.                       while (dwExitCode == STILL_ACTIVE) {
  31.                          WaitForSingleObject( pi.hProcess, 1000 );
  32.                          GetExitCodeProcess( pi.hProcess, &dwExitCode );
  33.                          SendMessage( hWnd, WM_USER, 0, (LPARAM)"Waiting for Calc to Finish" );
  34.                       }
  35.                       SendMessage( hWnd, WM_USER, 0, (LPARAM)"Calc is Finished" );
  36.                    }
  37.                }
  38.                break;
  39.                case IDM_EXIT:
  40.                    DestroyWindow( hWnd );
  41.                break;
  42.            }
  43.        break;
  44.        case WM_USER:
  45.                {  // Message to show synchronization actions.
  46.                   TCHAR szBuffer[101];
  47.                   static int row = 0;
  48.                   static int msg_num = 1;
  49.                   HDC hDC = GetDC( hWnd );
  50.                   FillMemory( szBuffer, 100, 32 );
  51.                   TextOut( hDC, 0, row, szBuffer, 100 );
  52.                   wsprintf( szBuffer, "%3d: %s", msg_num++, (LPTSTR)lParam );
  53.                   TextOut( hDC, 0, row, szBuffer, lstrlen( szBuffer ) );
  54.                   if ( row > 200 )
  55.                      row = 0;
  56.                   else
  57.                      row += 20;
  58.                   ReleaseDC( hWnd, hDC );
  59.                }
  60.                break;
  61.        case WM_DESTROY:
  62.                PostQuitMessage( 0 );
  63.                break;
  64.        default:
  65.            return DefWindowProc( hWnd, message, wParam, lParam );
  66.   }
  67.   return (NULL);
  68. }